cmake_minimum_required(VERSION 3.10)  # 建议使用最新稳定版

# ----------------------
# 基础配置
# ----------------------
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# 定义路径变量（明确项目结构）
set(PROJECT_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")
set(PROJECT_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src")

# # ----------------------
# # 依赖查找
# # ----------------------
# 查找 PCL 库
# find_package(PCL 1.8 REQUIRED COMPONENTS common visualization)
# if(PCL_FOUND)
#     message(STATUS "PCL found: ${PCL_VERSION}")
#     include_directories(${PCL_INCLUDE_DIRS})
#     link_directories(${PCL_LIBRARY_DIRS})
#     add_definitions(${PCL_DEFINITIONS})
# else()
#     message(FATAL_ERROR "PCL not found. Please install PCL library.")
# endif()

# ----------------------
# 静态库定义
# ----------------------
set(PT_SDK_LIBRARY ${PROJECT_NAME}_pt_static)
set(AI_COMMON_LIBRARY ${PROJECT_NAME}_common_static)
add_library(${PT_SDK_LIBRARY} STATIC
    ${PROJECT_SRC_DIR}/pointcloud_tools.cpp
    # ${PROJECT_SRC_DIR}/point_display.cpp
    ${PROJECT_SRC_DIR}/point_datagen.cpp
    ${PROJECT_SRC_DIR}/point_preprocess.cpp
)

# ----------------------
# 头文件管理
# ----------------------
target_include_directories(${PT_SDK_LIBRARY}
    PUBLIC  # 外部项目包含此路径即可使用库接口
        ${PROJECT_INCLUDE_DIR}
        ${PCL_INCLUDE_DIRS}
)

# 指定公共头文件（用于安装和IDE索引）
set_target_properties(${PT_SDK_LIBRARY} 
    PROPERTIES
    PUBLIC_HEADER "include/pointcloud_tools.h;include/point_common.h;include/point_datagen.h;include/point_preprocess.h"
)


# ----------------------
# 编译选项
# ----------------------
target_compile_options(${PT_SDK_LIBRARY} PRIVATE
    $<$<CXX_COMPILER_ID:GNU>:-Wall -Wextra -pedantic>  # GCC警告
    $<$<CXX_COMPILER_ID:Clang>:-Wall -Wextra -pedantic -Wno-unknown-pragmas>  # Clang警告
    $<$<CXX_COMPILER_ID:AppleClang>:-Wall -Wextra -pedantic -Wno-unknown-pragmas>  # Apple Clang警告
)

# ----------------------
# 依赖链接（静态库内部依赖）
# ----------------------
target_link_libraries(${PT_SDK_LIBRARY} 
    ${AI_COMMON_LIBRARY} 
    # PRIVATE
    ${PCL_LIBRARIES}
)

# ----------------------
# 安装配置（可选，用于打包）
# ----------------------
install(TARGETS ${PT_SDK_LIBRARY}
    ARCHIVE DESTINATION lib  # 静态库安装路径
    PUBLIC_HEADER DESTINATION include  # 头文件安装路径
)